package org.dromara.hmily.common.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * IOUtils.
 */
public class IOUtils {

    /**
     * inputStream转数组.
     * @param input 输入
     * @return byte数组
     * @throws IOException IO异常
     */
    public static byte[] convert(final InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        // 创建一个缓冲区大小为4096的字节数组
        byte[] buffer = new byte[4096];
        int bytesRead;

        while ((bytesRead = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }

        return output.toByteArray();
    }
}
